home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Progress Indicators
/
LAGAIndetermProgress.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
9KB
|
298 lines
// ===========================================================================
// LAGAIndetermProgress.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant Indeterminate progress indicator
// Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), but not remove this notice (no need to acknowledge the use of
// this class in the about box)
// You may not sell this source code in any form. This source code may be placed on
// publicly accessable archive sites and source code disks. It may not be placed on
// profit archive sites and source code disks without the permission of the author,
// Christophe ANDRES.
//
// This source code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// If you make any change or improvement on this class, please send the improved/changed
// version to : chrisoft@calva.net or Christophe ANDRES
// 20, rue Prosper Mérimée
// 67100 STRASBOURG
// FRANCE
//
// ===========================================================================
// LAGAIndetermProgress.h <- double-click + Command-D to see class declaration
//
// LAGAIndetermProgress is my implementation of the “Apple Grayscale Appearance for System 7.5”
// inderterminate progress indicator. The indicator spins automatically (through LPeridical)
// but can also be brought to "manual" spin, by calling the Spin method.
//
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/04/96 ca added RegisterClass method for easy registry
// Increased version to 1.2
// 05/21/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
// (version 1.1)
//
// To Do:
//
#include "LAGAIndetermProgress.h"
#include <UEnvironment.h>
#include "AGAColors.h"
const short kIndicatorHeight = 14;
const short kMinimumWidth = 16;
const short kImageHeight = 10;
const short kImageWidth = 16;
char LAGAIndetermProgress::mPattern[kImageHeight][kImageWidth] =
{
{ 10, 10, 10, 10, A, A, A, A, A, A, A, A, 10, 10, 10, 10 },
{ 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8 },
{ 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8, 8, 8, 8, 5, 5 },
{ 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 2 },
{ W, W, W, W, W, W, W, W, 3, 3, 3, 3, 3, 3, 3, 3 },
{ 5, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5, 5 },
{ 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8 },
{ 10, 10, 10, 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10, 10 },
{ A, A, A, A, 8, 8, 8, 8, 8, 8, 8, 8, A, A, A, A },
{ 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 12, 12, 12 }
};
PixMapHandle LAGAIndetermProgress::mImage = nil;
long LAGAIndetermProgress::mUsage = 0;
// static
void LAGAIndetermProgress::Initialise ()
{
Ptr bitsP;
Int32 n,i,j;
char color;
Rect radioSpace;
PixMapPtr pmp;
Int32 *scanP;
// Make a PixMapHandle for the image
bitsP = ::NewPtr(kImageHeight * kImageWidth * 4);
ThrowIfMemFail_(bitsP);
mImage = ::NewPixMap();
::HLockHi(Handle(mImage));
pmp = *mImage;
pmp->baseAddr = bitsP;
pmp->rowBytes = 0x8000 + kImageWidth * 4;
pmp->bounds.left = 0;
pmp->bounds.right = kImageWidth;
pmp->bounds.top = 0;
pmp->bounds.bottom = kImageHeight;
pmp->pmVersion = 0;
pmp->pixelType = RGBDirect;
pmp->pixelSize = 32;
pmp->cmpCount = 3;
pmp->cmpSize = 8;
pmp->planeBytes = 0;
::DisposeCTable(pmp->pmTable);
pmp->pmTable = nil;
pmp->pmReserved = 0;
// Fill it with the pixel array
scanP = (Int32*)bitsP;
for (i=0; i < kImageHeight; i++)
for (j=0; j < kImageWidth; j++)
{
color = mPattern[i][j];
*scanP++ = ((((Int32)gAGAColorArray[color].red)<<8) & 0xFF0000)
+((gAGAColorArray[color].green) & 0xFF00)
+((gAGAColorArray[color].blue>>8) & 0xFF);
}
}
// begin <06/04/96 ca>
void LAGAIndetermProgress::RegisterClass ()
{
URegistrar::RegisterClass(LAGAIndetermProgress::class_ID, (ClassCreatorFunc)LAGAIndetermProgress::CreateAGAIndetermProgressStream);
}
// end <06/04/96 ca>
LAGAIndetermProgress* LAGAIndetermProgress::CreateAGAIndetermProgressStream (LStream* inStream)
{
return (new LAGAIndetermProgress(inStream));
}
//-------Constructors-------------------------------------------------------------------------------------------------
LAGAIndetermProgress::LAGAIndetermProgress (LStream *inStream) : LPane(inStream)
{
mAnimationStep = 0;
inStream->ReadData(&mAnimationTicks, sizeof(Int32));
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
mUsage++;
if (mImage == nil)
Initialise();
}
LAGAIndetermProgress::LAGAIndetermProgress (const LAGAIndetermProgress &inOriginal) : LPane(inOriginal)
{
mAnimationStep = 0;
mAnimationTicks = inOriginal.mAnimationTicks;
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
mUsage++;
if (mImage == nil) // But since we copy a LAGAIndetermProgress, mImage MUST already be initialized ;)
Initialise();
}
LAGAIndetermProgress::LAGAIndetermProgress (const SPaneInfo &inPaneInfo, Int32 inTicksDelay) : LPane(inPaneInfo)
{
mAnimationStep = 0;
mAnimationTicks = inTicksDelay;
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
mUsage++;
if (mImage == nil)
Initialise();
}
LAGAIndetermProgress::~LAGAIndetermProgress ()
{
mUsage--;
if (mUsage)
{
if (mImage != nil)
{
::DisposePixMap(mImage);
mImage = nil;
}
}
}
void LAGAIndetermProgress::FinishCreateSelf ()
{
StartIdling();
}
//-------Drawers----------------------------------------------------------------------------------------------------
void LAGAIndetermProgress::DrawSelf ()
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Rect frame;
Rect r;
StClipRgnState theClip;
theState.Normalize();
CalcLocalFrameRect(frame);
frame.bottom = frame.top + kIndicatorHeight;
if (hasColor)
{
::RGBForeColor(&gAGAColorArray[5]);
::MoveTo(frame.left, frame.top + 12);
::Line(0, -12);
::LineTo(frame.right - 2, frame.top);
::ForeColor(whiteColor);
::Move(1, 1); ::Line(0, 12);
::LineTo(frame.left + 1, frame.bottom - 1);
}
::ForeColor(blackColor);
::InsetRect(&frame, 1, 1);
::FrameRect(&frame);
::InsetRect(&frame, 1, 1);
theClip.ClipToIntersection(frame);
short leftStart = frame.left - (mAnimationStep * 4);
::SetRect(&r, leftStart, frame.top, leftStart + kImageWidth, frame.top + kImageHeight);
if (hasColor)
{
GrafPtr thisPort;
Rect srcRect;
::GetPort(&thisPort);
::SetRect(&srcRect, 0, 0, kImageWidth, kImageHeight);
do
{
::CopyBits((BitMapPtr)*mImage, &thisPort->portBits, &srcRect, &r, srcCopy, nil);
r.left += kImageWidth;
r.right += kImageWidth;
}
while (r.left < frame.right);
}
else
{
PolyHandle thePoly = ::OpenPoly();
::MoveTo(0, 0);
::Line(7, 0);
::Line(10, 10);
::Line(-7, 0);
::Line(-10, -10);
::ClosePoly();
::OffsetPoly(thePoly, r.left - kImageWidth / 2, r.top);
do
{
::FillPoly(thePoly, &qd.white);
::OffsetPoly(thePoly, kImageWidth / 2, 0);
::FillPoly(thePoly, &qd.black);
::OffsetPoly(thePoly, kImageWidth / 2, 0);
r.left += kImageWidth;
r.right += kImageWidth;
}
while (r.left < (frame.right + kImageWidth));
KillPoly(thePoly);
}
mAnimationStep--;
if (mAnimationStep < 0)
mAnimationStep = 3;
}
void LAGAIndetermProgress::SpendTime (const EventRecord &inMacEvent)
{
static long time = 0;
if (::TickCount() > time)
{
if (FocusDraw())
{
Spin();
time = TickCount() + mAnimationTicks;
}
}
}
void LAGAIndetermProgress::Spin ()
{
if (FocusDraw())
DrawSelf();
}